from bert_score import score, score_simple
from bert_score import plot_example, plot_example_simple
from transformers import BertTokenizer,BertModel

# with open("hyps.txt") as f:
#     cands = [line.strip() for line in f]
#
# with open("refs.txt") as f:
#     refs = [line.strip() for line in f]
#
# (P, R, F), hashname = score(cands, refs, lang="en", return_hash=True)
# print(f"{hashname}: P={P.mean().item():.6f} R={R.mean().item():.6f} F={F.mean().item():.6f}")


out_put = '今天天气不错。'
ref = '今天天气非常好。'
model_dir = r'D:\work\deep_learning_model\chinese_wwm_ext_pytorch'
plot_example(out_put, ref,model_dir=model_dir, lang="zh")

tokenizer = BertTokenizer.from_pretrained(model_dir, do_lower_case=True)
model = BertModel.from_pretrained(model_dir)
# plot_example_simple(out_put, ref, model, tokenizer)

P, R, F = score_simple(
    [out_put],
    [ref],
    model,
    tokenizer)
print(P, R, F)

# (tensor([0.9578]), tensor([0.9435]), tensor([0.9506]))